(use ./common)
(def
  [ansi-move-at-sfx ansi-down-n-sfx ansi-left-n-sfx]
  ["H" "B" "D"])
(defn move-at (x y) #n,n
  (string ansi-pfx
          y ansi-sep x
          ansi-move-at-sfx))
(defn move-to (+x +y) #n,n
  (string ansi-pfx
          +y ansi-down-n-sfx
          ansi-pfx
          +x ansi-left-n-sfx))
(defn Rect (&opt w h x y text) #n,n,n,n,s
  (default w 1) (default h 1)
  (default x 0) (default y 0)
  (default text "")
  (if (some zero? [w h]) (errorf "RECT-ERROR-ZERO:WIDTH=%s.HEIGHT=%s" w h))
    (def s (string (move-at x y)
                   ;(interpose (move-to w 1)
                               (partition w (string/fit (* h w) text))))))
(defn Line (&opt w x y chars) #n,n,n,s of length>0
  (default x 0) (default y 0)
  (default w 0) (default chars "")
  (def s (string (move-at x y)
                 (string/resize chars w))))
(defn Collumn (&opt h x y chars) #n,n,n,s
  (Rect 1 h x y (string/resize chars h))) #im lazy, and?
#
(defn Outline (&opt w h x y chars) #n,n,n,n,s
  (default w 1) (default h 1)
  (default x 0) (default y 0)
  (default chars "")
  (if (some zero? [w h]) (errorf "RECT-ERROR-ZERO:WIDTH=%s.HEIGHT=%s" w h))
   (def s (string (Line w x y chars)
                  (Line (inc w) x (+ y h) chars) #inc for Corner.
                  (Collumn h x y chars)
                  (Collumn h (+ x w) y chars))))
(defn CLEAR ()
  (string ansi-pfx "2J")
  )
(defn get-term-size ()
  (map |(scan-number (string/trim (return-shell ["tput" $])))
                                 ["cols" "lines"]))
(def aligners {
               :left (fn always-0 (& _) 0)
               :right (fn always-max (& s) (length s))
               }) #TODO
#(defn Draw2DArray (&opt arr x y align) #*[&*[s]],w)
  #(def linejump (cond
 #                (= align :left) (point x)
 #                 (= align :right) (point
 #                                  (string/longest-length
 #                                   arr))
  #                (error "Unimplemented"))) #TODO::::::::
  #(def s (string ;(partition (move-at (linejump) )) )))
(def bigtext-map
  [;(array/new-filled 65)
`
.---.
|---|
|   |
` # TODO:::::::::
  ])
(defn bigtext (bytes)

  )
